<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script>
    //自学
    // concat() 方法用于合并两个或多个数组。
    // 此方法不会更改现有数组，而是返回一个新数组。
    var arr = [1, 2, 3];
    var arr2 = [4, 5, 6]
    // console.log(arr.concat(arr2));

    // arr.splice; 索引从1开始
    /*        splice() 方法通过删除
或替换现有元素或者原地添加新的元素来修改数组,
并以数组形式返回被修改的内容。此方法会改变原数组。
 
//重新排序
const newarr=[1,2,3,4,5,6];
 
const arr2=[];
for (let i = 0; i < this.arr.length; i++) {
//此方法返回的是被删除的数组
arr2.push(newarr.splice(parseInt(Math.random()*newarr.length),1)[0]);
}
this.arr=arr2
console.log(arr2);
*/

    // 从索引 2 的位置开始删除 0 个元素，插入“drum”
    var myFish = ["angel", "clown", "mandarin", "sturgeon"];
    var removed = myFish.splice(2, 0, "drum");

    // 运算后的 myFish: ["angel", "clown", "drum", "mandarin", "sturgeon"]
    // 被删除的元素: [], 没有元素被删除

    // 从索引 2 的位置开始删除 1 个元素，插入“trumpet”
    var myFish = ['angel', 'clown', 'drum', 'sturgeon'];
    var removed = myFish.splice(2, 1, "trumpet");

    // 运算后的 myFish: ["angel", "clown", "trumpet", "sturgeon"]
    // 被删除的元素: ["drum"]




    // arr.slice 方法返回一个新的数组对象 从0 开始
    /* ，这一对象是一个由 begin 和 end 
    浅拷贝 原数组不改变
    。 */
    const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];


    const animals2 = animals.slice(2)
    console.log(animals2, '改沟');
    console.log(animals, '原数组');
    // expected output: Array ["camel", "duck", "elephant"]

    console.log(animals.slice(2, 4));
    // expected output: Array ["camel", "duck"]

    console.log(animals.slice(1, 5));
    // expected output: Array ["bison", "camel", "duck", "elephant"]

    console.log(animals.slice(-2));
    // expected output: Array ["duck", "elephant"]

    console.log(animals.slice(2, -1));
    // expected output: Array ["camel", "duck"]

    console.log(animals.slice());
        // expected output: Array ["ant", "bison", "camel", "duck", "elephant"]
  </script>
</head>

<body>

</body>

</html>